/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InternetPanel.java
 *
 * Created on 18 Φεβ 2011, 9:10:37 πμ
 */
package tools.options;

import com.googlecode.svalidators.validators.NoSpaceValidator;
import com.googlecode.svalidators.validators.PositiveNumberValidator;
import com.googlecode.svalidators.validators.SValidator;

/**
 *
 * @author ssoldatos
 */
public class InternetPanel extends javax.swing.JPanel {

  /** Creates new form InternetPanel */
  public InternetPanel() {
    initComponents();
    setProxyDefaultStatus();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    cb_useProxy = new javax.swing.JCheckBox();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    tf_proxy = new com.googlecode.svalidators.formcomponents.STextField(new NoSpaceValidator("",false));
    tf_port = new com.googlecode.svalidators.formcomponents.STextField(new PositiveNumberValidator("",false,false));

    jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+2));
    jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel1.setText("Ρυθμίσεις Internet");

    cb_useProxy.setBackground(new java.awt.Color(255, 255, 255));
    cb_useProxy.setSelected(Options.toBoolean(Options.USE_PROXY));
    cb_useProxy.setText("Χρήση proxy server");
    cb_useProxy.setName(Options.USE_PROXY);
    cb_useProxy.setOpaque(false);
    cb_useProxy.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cb_useProxyActionPerformed(evt);
      }
    });

    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel2.setText("Proxy Server :");

    jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    jLabel3.setText("Port :");

    tf_proxy.setText(Options.toString(Options.PROXY_HOST));
    tf_proxy.setName(Options.PROXY_HOST);

    tf_port.setText(Options.toString(Options.PROXY_PORT));
    tf_port.setName(Options.PROXY_PORT);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
              .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(cb_useProxy, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addComponent(tf_port, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(tf_proxy, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(cb_useProxy)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(tf_proxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(tf_port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(68, Short.MAX_VALUE))
    );
  }// </editor-fold>//GEN-END:initComponents

  private void cb_useProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_useProxyActionPerformed
    setProxyDefaultStatus();
  }//GEN-LAST:event_cb_useProxyActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JCheckBox cb_useProxy;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private com.googlecode.svalidators.formcomponents.STextField tf_port;
  private com.googlecode.svalidators.formcomponents.STextField tf_proxy;
  // End of variables declaration//GEN-END:variables

  private void setProxyDefaultStatus() {
    tf_port.setEnabled(cb_useProxy.isSelected());
    tf_proxy.setEnabled(cb_useProxy.isSelected());
    if (!cb_useProxy.isSelected()) {
      tf_proxy.removeValidator(SValidator.NOSPACE);
      tf_proxy.removeValidator(SValidator.REQUIRED);
      tf_port.removeValidator(SValidator.POSITIVE);
      tf_port.removeValidator(SValidator.REQUIRED);
    } else {
      tf_proxy.addValidator(new NoSpaceValidator(Options.toString(Options.PROXY_HOST), false));
      tf_port.addValidator(new PositiveNumberValidator(Options.toString(Options.PROXY_PORT), false, false));
    }
    tf_proxy.validateValue();
    tf_port.validateValue();
  }
}
